// 审核计划表
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="年份" prop="planYear">
        <el-date-picker
          type="year"
          v-model="queryParams.planYear"
          format="yyyy"
          value-format="yyyy"
          :style="{ width: '100%' }"
          placeholder="请选择年度"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['secure:planExercise:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['secure:planExercise:edit']"
          >修改</el-button
        >
      </el-col> -->

      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['secure:planExercise:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="printBox"
          v-hasPermi="['secure:planExercise:print']"
          >打印</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      @selection-change="handleSelectionChange"
      fit
      v-loading="loading"
      border
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column min-width="200" show-overflow-tooltip label="年度">
        <template slot-scope="scope">
          <span>{{ scope.row.year }}年度生产安全事故应急预案演练计划</span>
        </template>
      </el-table-column>
      <el-table-column min-width="200" show-overflow-tooltip label="演练目的">
        <template slot-scope="scope">
          <span>{{ scope.row.purpose }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column show-overflow-tooltip label="内审组组长" min-width="120" prop="innerAuditPlan.leaderName" /> -->
      <!-- <el-table-column show-overflow-tooltip label="首次会议签到表" cneter="left" min-width="180">
        <template slot-scope="scope">
          <el-link v-if="scope.row.firstSignFile" @click="look(baseApi +scope.row.firstSignFile)" type="primary" :underline="false" target="_blank">
            <span class="el-icon-document"> 查看首次会议签到表 <i class="el-icon-edit"></i> </span>
          </el-link>
          <div v-else>暂未上传</div>
        </template></el-table-column>
      <el-table-column show-overflow-tooltip label="末次会议签到表" min-width="180" prop="endSignFile" cneter="left">
        <template slot-scope="scope">
          <el-link v-if="scope.row.endSignFile"  type="primary" @click="look(baseApi +scope.row.endSignFile)">
            查看末次会议签到表 <i class="el-icon-edit" ></i>
          </el-link>
          <div v-else>暂未上传</div>
        </template>
      </el-table-column> -->
      <!-- <el-table-column cneter="left" show-overflow-tooltip label="总结报告" min-width="180" prop="report">
        <template slot-scope="scope">
          <el-link v-if="scope.row.report" @click="handleFile(scope.row, 3)" type="primary">
            查看总结报告<i class="el-icon-edit" @click.stop="handleFile(scope.row, 3, true)"></i>
          </el-link>
          <div v-else>暂未上传</div>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.effectStatus" :active-value="1" :inactive-value="0"
            @change="handleStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="240"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['secure:planExercise:info']"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.status !='end'"
            v-hasPermi="['secure:planExercise:edit']"
            >修改</el-button
          >
          <!-- <el-dropdown
            size="mini"
            @command="(command) => handleCommand(command, scope.row)"
          >
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right"
              >更多</el-button
            >
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                command="handleDelete"
                icon="el-icon-delete"
                v-hasPermi="['secure:planExercise:remove']"
                >删除</el-dropdown-item
              >
              <el-dropdown-item
                command="handleCorrent"
                icon="el-icon-delete"
                v-hasPermi="['secure:planExercise:add:jc']"
                >创建纠错</el-dropdown-item
              >

              <el-dropdown-item
                v-hasPermi="['secure:planExercise:frist:file']"
                command="handleFileFirst"
                icon="el-icon-plus"
                >{{
                  !scope.row.firstSignFile ? "上传" : "查看"
                }}首次签到表</el-dropdown-item
              >
              <el-dropdown-item
                v-hasPermi="['secure:planExercise:last:file']"
                command="handleFileLast"
                icon="el-icon-plus"
                >{{
                  !scope.row.endSignFile ? "上传" : "查看"
                }}末次签到表</el-dropdown-item
              >
              <el-dropdown-item
                v-hasPermi="['secure:planExercise:report:file']"
                command="handleSummary"
                v-if="!scope.row.report"
                icon="el-icon-plus"
                >{{ !scope.row.report ? "上传" : "查看" }}总结</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :visible.sync="openFile"
      :title="type == 1 ? '首次签到表' : type == 2 ? '末次签到表' : '总结报告'"
      width="800"
      append-to-body
    >
      <el-form
        :disabled="isEdit"
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="medium"
        label-width="120px"
      >
        <el-form-item label="" prop="filePath">
          {{ formData.filePath }}
          <fileUpload
            :isDelete="!isEdit"
            v-model="formData.filePath"
          ></fileUpload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!isEdit">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="openFile = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 打印模板位置 -->
    <PrintBox
      :checkNum="9"
      :printRow="printList"
      :isVertical="true"
      id="printBox"
    >
      <template slot="title" slot-scope="scope">
        <div style="margin-bottom: 10px">
          {{ scope.item.year }}年度生产安全事故应急预案演练计划 STET/B/16-3
        </div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table
          style="border-collapse: collapse; table-layout: fixed; width: 100%"
          border="1"
          cellspacing="0"
          class="table-page custom-table"
        >
          <tr>
            <td colspan="1" width="15%">演练目的</td>
            <td colspan="7" width="85%">{{ scope.item.purpose }}</td>
          </tr>
          <tr>
            <td
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              colspan="1"
              width="15%"
            >
              演练预案
            </td>
            <td colspan="3" width="35%">
              {{ scope.item.vos[0].reservePlan }}
            </td>
            <td
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              colspan="1"
              width="15%"
            >
              演练负责人
            </td>
            <td colspan="3" width="35%">{{ scope.item.vos[0].leaderName }}</td>
          </tr>
          <tr
            v-for="i in scope.item.vos.length < 4
              ? 3
              : scope.item.vos.length - 1"
          >
            <td colspan="3" width="35%">
              {{ scope.item.vos[i] && scope.item.vos[i].reservePlan }}
            </td>
            <td colspan="3" width="35%">
              {{ scope.item.vos[i] && scope.item.vos[i].leaderName }}
            </td>
          </tr>
          <tr>
            <td
              colspan="1"
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              width="15%"
            >
              计划时间
            </td>
            <td colspan="3" width="35%">{{ scope.item.vos[0].planTime }}</td>
            <td
              colspan="1"
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              width="15%"
            >
              演练地点
            </td>
            <td colspan="3" width="35%">{{ scope.item.vos[0].place }}</td>
          </tr>
          <tr
            v-for="i in scope.item.vos.length < 4
              ? 3
              : scope.item.vos.length - 1"
          >
            <td colspan="3" width="35%">
              {{ scope.item.vos[i] && scope.item.vos[i].planTime }}
            </td>
            <td colspan="3" width="35%">
              {{ scope.item.vos[i] && scope.item.vos[i].place }}
            </td>
          </tr>
          <!-- 参与人员 -->
          <tr>
            <td
              colspan="1"
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              width="15%"
            >
              参与人员
            </td>
            <td colspan="7" width="85%">
              {{ scope.item.vos[0].joinUserName }}
            </td>
          </tr>
          <tr
            v-for="i in scope.item.vos.length < 4
              ? 3
              : scope.item.vos.length - 1"
          >
            <td colspan="7" width="85%">
              {{ scope.item.vos[i] && scope.item.vos[i].joinUserName }}
            </td>
          </tr>
          <!-- 准备工作 -->
          <tr>
            <td
              colspan="1"
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              width="15%"
            >
              准备工作
            </td>
            <td colspan="7" width="85%">{{ scope.item.vos[0].prepareWork }}</td>
          </tr>
          <tr
            v-for="i in scope.item.vos.length < 4
              ? 3
              : scope.item.vos.length - 1"
          >
            <td colspan="7" width="85%">
              {{ scope.item.vos[i] && scope.item.vos[i].prepareWork }}
            </td>
          </tr>
          <!-- 演练要求 -->
          <tr>
            <td
              colspan="1"
              :rowspan="scope.item.vos.length < 4 ? 4 : scope.item.vos.length"
              width="15%"
            >
              演练要求
            </td>
            <td colspan="7" width="85%">{{ scope.item.vos[0].requirement }}</td>
          </tr>
          <tr
            v-for="i in scope.item.vos.length < 4
              ? 3
              : scope.item.vos.length - 1"
          >
            <td colspan="7" width="85%">
              {{ scope.item.vos[i] && scope.item.vos[i].requirement }}
            </td>
          </tr>
        </table>
        <!-- 底部信息位置 -->

        <div
          class="desc"
          style="display: flex;
    text-align: left;;
    justify-content: space-around;
    margin-top: 17px;
}"
        >
          <div style="width: 30%">
            计划编制人：
            <img
              style="width: 50px"
              :src="$VUE_APP_IMG_API + scope.item.esign"
            />
          </div>
          <div style="width: 30%">
            批准人：
            <template v-if="CheckApprove(scope, 'zjl').ShowImg">
              <img
                style="width: 80px"
                :src="CheckApprove(scope, 'zjl').ApproveImg"
              />
            </template>
          </div>
          <div style="width: 30%">
            批准日期：{{ checkHistoryNode(scope, "zjl").endTime }}
          </div>
        </div>
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2023年12月1日起生效。</div>
        </div>
      </template>
    </PrintBox>
  </div>
</template>

<script>
import { listsafeAccidentDrill } from "@/api/secure/safeAccidentDrill.js";
import printStyle from "@/utils/print.js";

export default {
  name: "check",
  data() {
    return {
      isEdit: false,
      formData: { filePath: undefined },
      rules: {
        filePath: [
          {
            required: true,
            message: "附件不能为空",
            trigger: "change",
          },
        ],
      },
      baseApi: this.$VUE_APP_IMG_API,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planYear: undefined,
      },
      // 日期范围
      dateRange: [],
      openFile: false,
      type: 1,
      current: {},
      infos: [], //勾选的数据
      printList: [],
    };
  },
  created() {
    const str = sessionStorage.getItem("queryParams");
    console.log(JSON.parse(str));
    if (str) {
      this.queryParams = JSON.parse(str);
      setTimeout(() => {
        sessionStorage.removeItem("queryParams");
      }, 500);
    }
    this.getList();
  },
  methods: {
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        document.title = "年度生产安全事故应急预案演练计划 STET/B/16-3";

        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
          onPrintDialogClose: () => {
            document.title = process.env.VUE_APP_TITLE;
          },
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          height:11mm;
          padding: 4px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.safeAccidentDrillId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.infos = selection;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      const configId = row.safeAccidentDrillId || this.ids;
      this.$router.push("./addPlanExercise?isEdit=true&id=" + configId);
    },
    handleDetail(row) {
      this.$router.push(
        "./addPlanExercise?isInfo=true&id=" + row.safeAccidentDrillId
      );
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDelete":
          this.handleDelete(row);
          break;
        case "handleFileFirst":
          this.handleFile(row, 1);
          break;
        case "handleFileLast":
          this.handleFile(row, 2);
          break;
        case "handleSummary":
          this.handleFile(row, 3);
          break;
        case "handleCorrent":
          this.handleCorrent(row);
          break;
      }
    },
    handleCorrent(e) {
      sessionStorage.setItem("queryParams", JSON.stringify(this.queryParams));
      this.$router.push(
        "./addCorrect?safeAccidentDrillId=" + e.safeAccidentDrillId
      );
    },
    handleFile(row, type, isEdit = false) {
      try {
        this.formData = { filePath: undefined };
        this.type = type;
        this.current = row;
        this.isEdit = false;
        if (this.type == 1 && this.current.firstSignFile) {
          this.formData.filePath = this.current.firstSignFile;
          this.isEdit = true;
        }
        if (this.type == 2 && this.current.endSignFile) {
          this.formData.filePath = this.current.endSignFile;
          this.isEdit = true;
        }
        if (this.type == 3 && this.current.report) {
          this.formData.filePath = this.current.report;
          this.isEdit = true;
        }
        if (isEdit) this.isEdit = false;
      } catch (error) {
        console.log(error);
      }
      this.openFile = true;
    },
    handleStatusChange(row) {
      let text = row.effectStatus == "1" ? "启用" : "禁用";
      this.$modal
        .confirm(
          '确认要"' + text + '""' + row.safeAccidentDrillId + '"数据吗？'
        )
        .then(function () {
          return effectcheck(row.safeAccidentDrillId, row.effectStatus);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.effectStatus = row.effectStatus == "0" ? 1 : 0;
        });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.safeAccidentDrillId || this.ids;

      this.$modal
        .confirm(
          "是否确认删除" +
            row.innerAuditPlan.planYear +
            "年度内部工作计划数据项？"
        )
        .then(function () {
          return delcheck(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.$router.push("./addPlanExercise");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listsafeAccidentDrill(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startAuditDate",
          "endAuditDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    look(e) {
      window.open(e);
    },
    handleExport() {
      this.download(
        "/system/safeAccidentDrill/export",
        {
          ...this.queryParams,
        },
        `年度生产安全事故应急预案演练计划${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.formData.type = this.type;
          this.formData.safeAccidentDrillId = this.current.safeAccidentDrillId;
          signFile(this.formData).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.openFile = false;
            this.getList();
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
